/*
 * Created on Jun 6, 2005
 *
 */
package com.erclab.internal.xpresso.unittests;

import java.util.*;

import com.erclab.internal.xpresso.Application;
import com.erclab.internal.xpresso.*;
import com.erclab.internal.xpresso.exceptions.ApplicationException;
import com.erclab.internal.xpresso.exceptions.FormException;
import com.erclab.internal.xpresso.formelements.*;
import com.erclab.internal.xpresso.forms.*;

import junit.framework.TestCase;

/**
 * @author Enrique Rodriguez.
 *
 */
public class FlatFileApplicationTest extends TestCase {

	Application grad = null;

	/**
	 * Constructor for FlatFileApplication.
	 * @param arg0
	 */
	public FlatFileApplicationTest(String arg0) {
		super(arg0);
	}

	public void setUp() throws Exception{
		super.setUp();
		try {
			grad = new com.erclab.internal.xpresso.Application();
		} catch(ApplicationException e){
			fail("Create Application failed: " + e.toString());
		}
	}
	
	public void testCreateApplication(){
		assertTrue(grad.getApplicationName() != null);
		assertTrue(grad.getApplicationDescription() != null);
		
		System.out.println("testCreateApplication() -------------------------");
		System.out.println("ApplicationName: " + grad.getApplicationName());
		System.out.println("ApplicationDescription: " + grad.getApplicationDescription());
		
	}
	
	public void testCreateForm(){
	
		// Create a form using a form factory
		Form theForm = null;
		try {
			theForm = FormFactory.loadForm("Employees");
		} catch (FormException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			fail();
		}
		assertTrue(theForm != null);
		assertTrue(theForm.getFormName().equals("Employees"));
		
		System.out.println("testCreateAForm() -------------------------");
		System.out.println("Form info :");
		System.out.println(theForm.toString());
		
		// Test and print the elements
		ArrayList formElements = theForm.getFormElements();
		if (formElements == null){
			System.out.println("No form elements for this form");
		}
		
		for (Iterator iter = formElements.iterator(); iter.hasNext();) {
			FormElement fe = (FormElement)iter.next();
			System.out.println("Destination of the element -->" + fe.getDestinationColumn());
		}
	}

}
